<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\AsrCallSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="asr-call-index">

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            ['attribute' =>'line',
                'footer' => '
                    <input id="num" class="btn btn-default btn-xs btn-delete" placeholder="每页显示的条数" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,\'\')}else{this.value=this.value.replace(/\D/g,\'\')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,\'\')}else{this.value=this.value.replace(/\D/g,\'\')}">
                ',
                'options'=>[
                    'width'=>'15%',
                ],
            ],
            'number',
            ['attribute' => 'create_at',
                'value'=>
                    function($model){
                        return  date('Y-m-d H:i:s',$model->create_at);   //主要通过此种方式实现
                    },
            ],
            'operator',
            ['attribute' => 'duration',
                'value'=>
                    function($model){
                        return  (int)($model->duration/60)."分钟";   //主要通过此种方式实现
                    },
            ],
            ['class' => 'yii\grid\ActionColumn',//下面是新增加的按按钮
                'header'=>'操作',

                    'template' => ' {forbidden} ',
                    'buttons' => [
                        'forbidden' => function ( $url,$model) {
                            if($model->status == 0){
                                return  '<a href="'.$url.'" class="btn btn-danger">禁用</a>';
                            }else{
                                return  '<a href="'.$url.'" class="btn btn-success">启用</a>';
                            }

                        },
                    ],
                'options'=>[
                    'width'=>'20%',
                ],
                'footerOptions' => ['colspan' => 1],  //设置删除按钮垮列显示；

            ],
        ],
        'filterModel' => $searchModel,
        'showFooter' => true,  //设置显示最下面的footer
        'pager'=>[
            'firstPageLabel'=>"第一页",
            'lastPageLabel'=>'最后一页',
        ],
    ]); ?>
</div>

<script>
    $(function () {
        var Default = {
            animationSpeed: 500,
        }
        //自定义分页
        $("#num").blur(function(){//当鼠标失去焦点时就出发事件，实现分页的页改变
            var url = "index";
            //alert(url);
            $.ajax({
                type:"post",
                async:true,
                cache:false,
                url:url,/*url写异域的请求地址*/
                data:{
                    pageSize:$("#num").val()
                },
                success: function(datas){
                    window.location.reload()
                },
                error: function(error){
                }
            });
        });
    });
</script>
